﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NPOI.SS.UserModel;
using System.Reflection;
namespace IHISCETeim.Library
{
    /// <summary>
    /// 导出EXCEL时,根据实体类的数据类型自动转换EXCEL的数据类型
    /// </summary>
    public class ConvertDateTypeHelper
    {
        public static void WriteExcelDateType(ICell cell, string PropertyTypeString,object PropertyValue)
        {
            switch (PropertyTypeString)
            {
                case "System.Int16":
                case "System.Int32":
                case "System.Int64":
                case "System.Single":
                case "System.Double":
                case "System.Decimal":
                case "System.Byte":
                    cell.SetCellValue(Convert.ToDouble(PropertyValue));
                    break;
                case "System.DateTime":
                    cell.SetCellValue(Convert.ToDateTime(PropertyValue));
                    break;
                case "System.Boolean":
                    cell.SetCellValue(Convert.ToBoolean(PropertyValue));
                    break;
                case "System.String":
                case "System.Char":
                    cell.SetCellValue( System.Web.HttpUtility.HtmlDecode( StringHelper.StripTags(Convert.ToString(PropertyValue),true)));
                    break;
                default:
                    cell.SetCellValue(System.Web.HttpUtility.HtmlDecode(Convert.ToString(PropertyValue)));
                    break;
            }
        }
        public static void WriteExcelDateType(ICell cell, PropertyInfo objPropertyInfo, object PropertyValue)
        {

            WriteExcelDateType(cell, objPropertyInfo.PropertyType.ToString(), PropertyValue);           
        }
    }
}
